package io.renren.modules.jxgk.controller;

import io.renren.common.annotation.SysLog;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.jxgk.entity.SchoolAnnouncementEntity;
import io.renren.modules.jxgk.service.SchoolAnnouncementService;
import io.renren.modules.jxgk.utils.UUidCreater;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("SchoolAnnouncement/")
public class SchoolAnnouncementController {

    @Autowired
    SchoolAnnouncementService schoolAnnouncementService;

    @RequestMapping("Select")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<SchoolAnnouncementEntity> cse = schoolAnnouncementService.queryList(query);
        int total = schoolAnnouncementService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(cse, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }
    @RequestMapping("/Delete")
    public R delete(@RequestBody String[] indexs){
        schoolAnnouncementService.deleteBatch(indexs);
        return R.ok();
    }
    @RequestMapping("/Insert")
    public R save(@RequestBody SchoolAnnouncementEntity ste){
        UUidCreater u=new UUidCreater();
        String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
        ste.setSchoolAnnouncementId(u.getUUID());
        ste.setSchoolAnnouncementCreater(username);
        schoolAnnouncementService.save(ste);
        return R.ok();
    }
    @RequestMapping("/Info/{index}")
    public R info(@PathVariable("index") String index){
        SchoolAnnouncementEntity cse = schoolAnnouncementService.queryObject(index);
        return R.ok().put("SchoolAnnouncement", cse);
    }
    @SysLog("修改用户")
    @RequestMapping("/Update")
    public R update(@RequestBody SchoolAnnouncementEntity cse){
        schoolAnnouncementService.update(cse);
        return R.ok();
    }
}